package com.blackitheima.test1;

import java.util.HashMap;
import java.util.Map;

public class MyHashMap2 {
    public static void main(String[] args) {
        Map<String,String> map=new HashMap<>();
        map.put("郭靖","黄蓉");
        map.put("灰太狼","红太狼");
        map.put("唐雷","蓝银草");

        //put 添加  若键重复则值会转换并返回现有值
        String s = map.put("郭靖", "小花花");
        System.out.println(s);
        System.out.println(map);

        //remove 删除指定键的键值对
        String s1 = map.remove("郭靖");
        System.out.println(s1);
        System.out.println(map);

        //containsKey 判断指定键是否存在
        boolean key1 = map.containsKey("郭靖");
        boolean key2 = map.containsKey("唐雷");
        System.out.println(key1);
        System.out.println(key2);

        //containsValue 判断指定值是否存在
        boolean value1 = map.containsValue("红太狼");
        boolean value2 = map.containsValue("小花花");

        //clear 删除集合
        map.clear();
        System.out.println(map);

        //isEmpty 判断集合是否为空
        boolean empty = map.isEmpty();
        System.out.println(empty);

        //size() 判断长度
        int size = map.size();
        System.out.println(size);
    }
}
